package com.huawo.opensdk;

import android.annotation.SuppressLint;
import android.util.Log;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.huawo.opensdk.bean.ConnectDevice;


@SuppressLint("CheckResult")
public class DeviceConnectManager {

    private static ConnectDevice connectDevice;
    private static MutableLiveData<ConnectDevice> connectDeviceMutableLiveData = new MutableLiveData<>();
    private static MutableLiveData<Boolean> connectBtDeviceMutableLiveData = new MutableLiveData<>();
//    private static SingleLiveEvent<ConnectDevice> connectDeviceOTALiveData = new SingleLiveEvent<>();

    public static ConnectDevice getConnectDevice() {
        return connectDevice;
    }

    public static LiveData<Boolean> getRefreshBtDeviceLiveData() {
        return connectBtDeviceMutableLiveData;
    }


    public static LiveData<ConnectDevice> getConnectDeviceLiveData() {
        return connectDeviceMutableLiveData;
    }

    public static void setRefreshBtDeviceMutableLiveData(Boolean connectBtDevice) {
        connectBtDeviceMutableLiveData.postValue(connectBtDevice);
    }

    public static synchronized void setConnectDevice(ConnectDevice connectDevice) {
        try {
            Log.i("DeviceConnectManager", "【DeviceConnectManager】设置连接状态：" + connectDevice);
            DeviceConnectManager.connectDevice = connectDevice;

            if (null != connectDevice) {
//                DeviceGoalPreferences.setDeviceAdapter(connectDevice.deviceType);
            }

            connectDeviceMutableLiveData.postValue(connectDevice);
//            connectDeviceOTALiveData.postValue(connectDevice);
            Log.i("DeviceConnectManager", "【DeviceConnectManager】设置连接状态 -> 成功");
        } catch (Exception e) {
            Log.e("DeviceConnectManager", "【DeviceConnectManager】设置连接状态 -> 失败", e);
            throw e;
        }
    }
}